package com.example.education.Controller;


import com.example.education.Bean.News;
import com.example.education.Bean.packaginggroup.PackagingString;
import com.example.education.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 姚
 * @since 2023-04-12
 */
@RestController
@RequestMapping("/news")
@CrossOrigin
public class NewsController {

    @Autowired
    private NewsService newsService;


    //展现所有新闻
    @RequestMapping("/show")
    public ArrayList<News> show() throws Exception {
        return newsService.selectAllNews();
    }

    //新闻推荐
    @RequestMapping("/recommend")
    public ArrayList<News> recommend(@RequestBody(required = false) PackagingString packagingString) throws Exception {
//        newsService.recommend(newsService.getDataModel());
        System.out.println(packagingString.getString());
        System.out.println(newsService.recommendNews(packagingString.getString()));
        return newsService.recommendNews(packagingString.getString());
    }

    //根据阶段推荐新闻
    @RequestMapping("/recommendByStage")
    public ArrayList<News> recommendByStage(@RequestBody(required = false) PackagingString packagingString) throws Exception {
        System.out.println(packagingString.getString());
        return newsService.recommendNewsByStage(packagingString.getString());
    }

}

